package com.zr.d_c.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zr.d_c.model.Customer;
import com.zr.d_c.model.User;
import com.zr.d_c.service.UserInfoService;
import com.zr.d_c.service.UserService;
import com.zr.d_c.serviceimpl.UserInfoServiceImpl;
import com.zr.d_c.serviceimpl.UserServiceImpl;
/**
 * 修改顾客信息
 * @author Administrator
 *
 */
public class ModifyCinfoController extends HttpServlet{
	UserInfoService userinfoservice = new UserInfoServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		req.setCharacterEncoding("utf-8");
		String cname = req.getParameter("cname");
		String cage = req.getParameter("cage");
		String csex = req.getParameter("csex");
		String cphone = req.getParameter("cphone");
		String cemail = req.getParameter("cemail");
		HttpSession session = req.getSession();
		User u = (User) session.getAttribute("currentUser");
		int uid = u.getUid();
		Customer customer = new Customer(cname, cage, csex, cphone, cemail, uid);
		int i = userinfoservice.modifyCurrentUserInfoByUid(customer);
		PrintWriter pw = resp.getWriter();
		session.setAttribute("currentUserName", cname);
		if(i==1){
			pw.write("1");
		}else{
			pw.write("0");
		}
		pw.flush();
		pw.close();
	}
}
